/*
 * @Author: c
 * @Date: 2024-01-15 00:59:42
 * @LastEditTime: 2024-03-22 06:20:42
 * @LastEditors: c
 * @Description:
 * @FilePath: \music-web-admin\src\api\application\artist\index.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Delete, Download, Get, Post, Put } from "@/http/http";
import { AlbumQuery, ArtistForm, ArtistPageVO, ArtistQuery } from "./types";

/**
 * 获取歌手分页列表
 *
 * @param queryParams
 */
export function getArtistPage(
  queryParams: ArtistQuery
): Promise<PageResult<ArtistPageVO[]>> {
  return Get<ArtistQuery, PageResult<ArtistPageVO[]>>(
    "/api/v1/artist/page",
    queryParams
  );
}

/**
 * 获取歌手下拉列表
 *
 * @param queryParams
 */
export function listArtistOptions(
  queryParams: ArtistQuery
): Promise<OptionType[]> {
  return Get<ArtistQuery, OptionType[]>("/api/v1/artist/options", queryParams);
}

/**
 * 获取专辑下拉列表
 *
 * @param queryParams
 */
export function listAlbumOptions(
  queryParams: AlbumQuery
): Promise<OptionType[]> {
  return Get<AlbumQuery, OptionType[]>("/api/v1/album/options", queryParams);
}

/**
 * 获取歌手表单详情
 *
 * @param artistId
 */
export function getArtistForm(artistId: number): Promise<ArtistForm> {
  return Get<number, ArtistForm>("/api/v1/artist/" + artistId + "/form");
}

/**
 * 添加歌手
 *
 * @param data
 */
export function addArtist(data: any) {
  return Post("/api/v1/artist", data);
}

/**
 * 修改歌手
 *
 * @param id
 * @param data
 */
export function updateArtist(id: number, data: ArtistForm) {
  return Put("/api/v1/artist/" + id, data);
}

/**
 * 删除歌手
 *
 * @param ids
 */
export function deleteArtists(ids: string) {
  return Delete("/api/v1/artist/" + ids, {});
}

/**
 * 下载歌手导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
  return Download("/api/v1/artist/template", null, "arraybuffer");
}

/**
 * 导出歌手
 *
 * @param queryParams
 * @returns
 */
export function exportArtist(queryParams: ArtistQuery) {
  return Download("/api/v1/artist/_export", queryParams, "arraybuffer");
}

/**
 * 导入歌手
 *
 * @param file
 */
export function importArtist(file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return Post("/api/v1/artist/_import", formData);
}
